package model

import (
	"database/sql"
	"time"

	"github.com/guregu/null"
	"github.com/satori/go.uuid"
)

var (
	_ = time.Second
	_ = sql.LevelDefault
	_ = null.Bool{}
	_ = uuid.UUID{}
)

/*
DB Table Details
-------------------------------------


CREATE TABLE "invoice_items"
(
    [InvoiceLineId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [InvoiceId] INTEGER  NOT NULL,
    [TrackId] INTEGER  NOT NULL,
    [UnitPrice] NUMERIC(10,2)  NOT NULL,
    [Quantity] INTEGER  NOT NULL,
    FOREIGN KEY ([InvoiceId]) REFERENCES "invoices" ([InvoiceId])
		ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([TrackId]) REFERENCES "tracks" ([TrackId])
		ON DELETE NO ACTION ON UPDATE NO ACTION
)

JSON Sample
-------------------------------------
{    "invoice_line_id": 30,    "invoice_id": 80,    "track_id": 11,    "unit_price": 0.13639347552478345,    "quantity": 56}



*/

// InvoiceItems struct is a row record of the invoice_items table in the main database
type InvoiceItems struct {
	//[ 0] InvoiceLineId                                  integer              null: false  primary: true   isArray: false  auto: true   col: integer         len: -1      default: []
	InvoiceLineID int32 `gorm:"primary_key;AUTO_INCREMENT;column:InvoiceLineId;type:integer;" json:"invoice_line_id"`
	//[ 1] InvoiceId                                      integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	InvoiceID int32 `gorm:"column:InvoiceId;type:integer;" json:"invoice_id"`
	//[ 2] TrackId                                        integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	TrackID int32 `gorm:"column:TrackId;type:integer;" json:"track_id"`
	//[ 3] UnitPrice                                      numeric              null: false  primary: false  isArray: false  auto: false  col: numeric         len: -1      default: []
	UnitPrice float64 `gorm:"column:UnitPrice;type:numeric;" json:"unit_price"`
	//[ 4] Quantity                                       integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	Quantity int32 `gorm:"column:Quantity;type:integer;" json:"quantity"`
}

var invoice_itemsTableInfo = &TableInfo{
	Name: "invoice_items",
	Columns: []*ColumnInfo{

		{
			Index:              0,
			Name:               "InvoiceLineId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       true,
			IsAutoIncrement:    true,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "InvoiceLineID",
			GoFieldType:        "int32",
			JSONFieldName:      "invoice_line_id",
			ProtobufFieldName:  "invoice_line_id",
			ProtobufType:       "int32",
			ProtobufPos:        1,
		},

		{
			Index:              1,
			Name:               "InvoiceId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "InvoiceID",
			GoFieldType:        "int32",
			JSONFieldName:      "invoice_id",
			ProtobufFieldName:  "invoice_id",
			ProtobufType:       "int32",
			ProtobufPos:        2,
		},

		{
			Index:              2,
			Name:               "TrackId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "TrackID",
			GoFieldType:        "int32",
			JSONFieldName:      "track_id",
			ProtobufFieldName:  "track_id",
			ProtobufType:       "int32",
			ProtobufPos:        3,
		},

		{
			Index:              3,
			Name:               "UnitPrice",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "numeric",
			DatabaseTypePretty: "numeric",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "numeric",
			ColumnLength:       -1,
			GoFieldName:        "UnitPrice",
			GoFieldType:        "float64",
			JSONFieldName:      "unit_price",
			ProtobufFieldName:  "unit_price",
			ProtobufType:       "float",
			ProtobufPos:        4,
		},

		{
			Index:              4,
			Name:               "Quantity",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "Quantity",
			GoFieldType:        "int32",
			JSONFieldName:      "quantity",
			ProtobufFieldName:  "quantity",
			ProtobufType:       "int32",
			ProtobufPos:        5,
		},
	},
}

// TableName sets the insert table name for this struct type
func (i *InvoiceItems) TableName() string {
	return "invoice_items"
}

// BeforeSave invoked before saving, return an error if field is not populated.
func (i *InvoiceItems) BeforeSave() error {
	return nil
}

// Prepare invoked before saving, can be used to populate fields etc.
func (i *InvoiceItems) Prepare() {
}

// Validate invoked before performing action, return an error if field is not populated.
func (i *InvoiceItems) Validate(action Action) error {
	return nil
}

// TableInfo return table meta data
func (i *InvoiceItems) TableInfo() *TableInfo {
	return invoice_itemsTableInfo
}
